<?php

namespace App\Admin\Controllers;

use App\model\RobotConfig;
use App\Project;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class RobotConfigContoller extends AdminController
{
    protected       $states = [
        'on'  => ['value' => 0, 'text' => '启用', 'color' => 'success'],
        'off' => ['value' => 1, 'text' => '禁用', 'color' => 'danger'],
    ];
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '今日简报机器人';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new RobotConfig());

        $grid->column('project.name', __('发送项目'));
        $grid->column('key', __('Key'));

        $grid->column('send_time', __('每天发送时间'));
        $grid->column('is_display', __('是否禁用'))->switch($this->states);
        $grid->column('name', __('备注'));
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(RobotConfig::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('Name'));
        $show->field('key', __('Key'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('project_id', __('Project id'));
        $show->field('is_display', __('Is display'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new RobotConfig());
        $form->select('project_id', __('发送项目'))->options(Project::getSelectOptions())->required();

        $form->text('key', __('机器人的key'))->required();
        $form->time('send_time', __('发送时间'))->required();
        $form->text('name', __('备注'));

        $form->switch('is_display', __('启用禁用'))->states($this->states)->default(0)->required();

        return $form;
    }
}
